package cn.iocoder.yudao.module.product.job;

import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
import cn.iocoder.yudao.module.statistics.api.statistics.ProductStatisticsApi;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class SalesCountJob implements JobHandler {



    @Resource
    ProductSpuMapper productSpuMapper;

    @Resource
    ProductStatisticsApi productStatisticsApi;

    @Override
    public String execute(String param) {

        productSpuMapper.selectList().forEach(x -> {
            Integer count = productStatisticsApi.getProductSalesCount(x.getId());
            x.setSalesCount(count);
            productSpuMapper.updateById(x);

            System.out.println("更新销量：" +count );
        });
        return "执行价格更新" ;
    }

}